package cn.wolfcode.cms.service.impl;

import cn.wolfcode.cms.domain.ProductSort;
import cn.wolfcode.cms.mapper.ProductSortMapper;
import cn.wolfcode.cms.query.QueryObject;
import cn.wolfcode.cms.service.IProductSortService;
import cn.wolfcode.cms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductSortServiceImpl implements IProductSortService {

    @Autowired
    private ProductSortMapper productSortMapper;

    public void save(ProductSort entity) {
        productSortMapper.insert(entity);

    }

    public void update(ProductSort entity) {
        productSortMapper.updateByPrimaryKey(entity);
    }

    public void delete(Long id) {
        productSortMapper.deleteByPrimaryKey(id);
    }

    public ProductSort get(Long id) {
        return productSortMapper.selectByPrimaryKey(id);
    }

    public List<ProductSort> list() {
        return productSortMapper.selectAll();
    }

    public Object query(QueryObject qo) {
        //查总数
        int total = productSortMapper.queryForCount(qo);
        if(total == 0){
            return new PageResult();
        }
        //查数据
        List<ProductSort> rows = productSortMapper.queryForList(qo);
        return new PageResult(total, rows);
    }

}
